package com.hunan.api.catv.service.biz.apple;

import com.google.gson.JsonObject;
import com.hunan.api.catv.common.ConstantsMsg;
import com.hunan.api.catv.entity.ServiceResult;
import com.hunan.api.catv.service.ResultService;
import com.hunan.api.catv.service.impl.apple.AppleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class AppleBiz extends ResultService {

    @Autowired
    AppleService appleService;

    public ServiceResult verify(String token) {
        boolean flag = false;
        try {
            flag = appleService.verify(token);
        } catch (Exception e) {
            log.error("{}", e);
        }
        return build("", "", flag);
    }

    public ServiceResult getUserInfo(String token) {
        JsonObject userInfo = appleService.parserIdentityToken(token);
        if (!ObjectUtils.isEmpty(userInfo) && !ObjectUtils.isEmpty(userInfo.get("sub"))) {
            return buildOK(userInfo, "");
        }
        return buildFail(ConstantsMsg.getUserInfo_fail);
    }
}
